package cn.rubintry.bug.hunting.activity

import android.annotation.SuppressLint
import android.content.Intent
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.BounceInterpolator
import cn.rubintry.animate.AnimateUtils
import cn.rubintry.animate.core.IAnimatorInterface
import cn.rubintry.animate.core.listener.OnAnimationListener
import cn.rubintry.animate.core.param.AnimatorParam
import cn.rubintry.animate.core.param.AnimatorType
import cn.rubintry.animate.core.param.Value
import cn.rubintry.bug.common.base.BaseActivity
import cn.rubintry.bug.hunting.databinding.ActivitySplashBinding
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.SizeUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

@SuppressLint("CustomSplashScreen")
class SplashActivity : BaseActivity<ActivitySplashBinding>() {

    override fun bindingClazz(): Class<ActivitySplashBinding> {
        return ActivitySplashBinding::class.java
    }

    override fun getActivityParams() {

    }

    override fun initView() {
        AnimateUtils.with(binding?.imageView)
            .translation((ScreenUtils.getScreenWidth()) / 2f + SizeUtils.dp2px(100f) , 0f , false)
            .setDuration(3000)
            .start()


        AnimateUtils.with(binding?.imageView)
            .rotate( 450f , false)
            .setInterpolator(AccelerateDecelerateInterpolator())
            .setDuration(3200)
            .start()

        CoroutineScope(Dispatchers.Main).launch {
            delay(3500)
            val animateParams = Value()
            animateParams.put(AnimatorType.TRANSLATION , AnimatorParam.OFFSET_X , ScreenUtils.getScreenWidth() / 2f + SizeUtils.dp2px(150f))
            animateParams.put(AnimatorType.TRANSLATION , AnimatorParam.OFFSET_Y , 0f)
            animateParams.put(AnimatorType.TRANSLATION , AnimatorParam.REVERSE , false)
            animateParams.put(AnimatorType.ALPHA , AnimatorParam.FROM_ALPHA , 0f)
            animateParams.put(AnimatorType.ALPHA , AnimatorParam.TO_ALPHA , 1f)
            animateParams.put(AnimatorType.ALPHA , AnimatorParam.REVERSE , false)
            AnimateUtils.with(binding?.imgKeqing)
                .multiAnimation()
                .enableTranslation()
                .enableAlpha()
                .load(animateParams)
                .setDuration(200)
                .addListener(object : OnAnimationListener{
                    override fun onEnd() {
                        AnimateUtils.with(binding?.imageView)
                            .alpha(1f , 0f , false)
                            .setDuration(200)
                            .addListener(object : OnAnimationListener{
                                override fun onEnd() {
                                    val mulAnimateParam = Value()
                                    mulAnimateParam.put(AnimatorType.ALPHA , AnimatorParam.FROM_ALPHA , 1f)
                                    mulAnimateParam.put(AnimatorType.ALPHA , AnimatorParam.TO_ALPHA , 0f)
                                    mulAnimateParam.put(AnimatorType.ALPHA , AnimatorParam.REVERSE , false)
                                    mulAnimateParam.put(AnimatorType.SCALE , AnimatorParam.FROM_SCALE , 1f)
                                    mulAnimateParam.put(AnimatorType.SCALE , AnimatorParam.TO_SCALE , 5f)
                                    mulAnimateParam.put(AnimatorType.SCALE , AnimatorParam.REVERSE , false)
                                    AnimateUtils.with(binding?.imgKeqing)
                                        .multiAnimation()
                                        .enableAlpha()
                                        .enableScale()
                                        .load(mulAnimateParam)
                                        .setDuration(800)
                                        .addListener(object : OnAnimationListener{
                                            override fun onEnd() {
//                                                startActivity(Intent(this@SplashActivity , MainActivity::class.java))
//                                                finish()
                                            }

                                        })
                                        .start()
                                }

                            })
                            .start()
                    }

                })
                .start()
        }
    }

    override fun observeData() {

    }

    override fun onNetWorkError(msg: String?) {

    }


}